#include <iostream>
#include "BinaryTree.h"
using namespace std;

void CreateBinaryTreeBody(const vector<int> &array, int begin, int end, BinaryTree **root);
//array must be sorted ASC,this binary tree is balanced created
void CreateBinaryTree(const vector<int> &array, BinaryTree **root) {
	CreateBinaryTreeBody(array, 0, array.size() - 1, root);
}

void CreateBinaryTreeBody(const vector<int> &array, int begin, int end, BinaryTree **root) {
	if (begin > end)
		return;

	int mid = (begin + end) / 2;
	*root = new BinaryTree;
	(*root)->data = array[mid];
	(*root)->leftchild = NULL;
	(*root)->rightchild = NULL;
	CreateBinaryTreeBody(array, begin, mid - 1, &(*root)->leftchild);
	CreateBinaryTreeBody(array, mid + 1, end, &(*root)->rightchild);
}


